package com.one.controller;

import com.one.service.CollectFootpointService;
import com.one.util.PageUtil;
import com.one.util.RequestReturn;
import com.one.vo.CollectFootpointVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: CollectiFootpointContreoller
 * @Auther: yph
 * @Date: 2022/1/19 14:12
 * @Description: 用户收藏和足迹 服务端控制层
 */
@RestController
@RequestMapping("/user")
public class CollectFootpointController {
    @Autowired
    private CollectFootpointService collectFootpointService;

    /**
     * @Author: yph
     * @Date: 2022/1/19 14:14
     * @return:
     * @Description: 查询用户足迹最近一个月内的足迹信息
     */
    @GetMapping("/queryFootpoint")
    public RequestReturn<PageUtil<List<CollectFootpointVo>>> queryFootpointByUserId(@RequestParam(value = "userId", required = true) Integer userId,
                                                                                    @RequestParam(value = "pageNo", required = false) Integer pageNo,
                                                                                    @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        return collectFootpointService.queryFootpointByUserId(userId, pageNo, pageSize);
    }

    /**
     * @Author: yph
     * @Date: 2022/1/19 15:26
     * @return:
     * @Description: 收藏/取消商品
     */
    @GetMapping("/collectProduct")
    public RequestReturn<String> collectProduct(@RequestParam("userId") Integer userId,
                                                @RequestParam("productId") Integer productId) {
        return collectFootpointService.collectProductToRedis(userId, productId);
    }

    /**
     * @Author: yph
     * @Date: 2022/1/19 15:26
     * @return:
     * @Description: 收藏/取消商品
     */
    @GetMapping("/collectProducts")
    public RequestReturn<String> collectProduct(@RequestParam("userId") Integer userId,
                                                @RequestParam("productIds") List<Integer> productIds) {
        return collectFootpointService.collectProductsToRedis(userId, productIds);
    }

    /**
     * @Author: yph
     * @Date: 2022/1/19 18:24
     * @return:
     * @Description: 查询用户收藏的记录
     */
    @GetMapping("/queryCollectProduct")
    public RequestReturn<List<CollectFootpointVo>> queryCollectProduct(@RequestParam("userId") Integer userId) {
        return collectFootpointService.queryCollectProduct(userId);
    }

    /**
     * @Author: yph
     * @Date: 2022/1/21 22:35
     * @return:
     * @Description: 清空收藏夹
     */
    @GetMapping("/clearUserCollect/{userId}")
    public RequestReturn<String> clearUserCollect(@PathVariable("userId") Integer userId) {
        return collectFootpointService.clearUserCollect(userId);
    }
    
    /**
     * @Author: yph
     * @Date: 2022/1/21 23:59
     * @return: 
     * @Description: 清空足迹
    */
    @GetMapping("/clearUserFootPoint/{userId}")
    public RequestReturn<String> clearUserFootPoint(@PathVariable("userId") Integer userId) {
        return collectFootpointService.clearUserFootPoint(userId);
    }

}
